home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Science / Gnuplot 3.5 / docs / checkdoc.c next >
C/C++ Source or Header  |  1993-11-03  |  2KB  |  94 lines

  1. #ifndef lint
  2. static char *RCSid = "$Id: checkdoc.c%v 3.38.2.70 1993/02/08 02:19:29 woo Exp woo $";
  3. #endif
  4.  
  5.  
  6. /*
  7.  * checkdoc -- check a doc file for correctness of first column. 
  8.  *
  9.  * Prints out lines that have an illegal first character.
  10.  * First character must be space, digit, or ?, @, #, %, 
  11.  * or line must be empty.
  12.  *
  13.  * usage: checkdoc [docfile]
  14.  * Modified by Russell Lang from hlp2ms.c by Thomas Williams 
  15.  *
  16.  * Original version by David Kotz used the following one line script!
  17.  * sed -e '/^$/d' -e '/^[ 0-9?@#%]/d' gnuplot.doc
  18.  *
  19.  */
  20.  
  21. #include <stdio.h>
  22. #include <ctype.h>
  23.  
  24. #define MAX_LINE_LEN    256
  25. #define TRUE 1
  26. #define FALSE 0
  27.  
  28. main(argc,argv)
  29. int argc;
  30. char **argv;
  31. {
  32. FILE * infile;
  33.     infile = stdin;
  34.     if (argc > 2) {
  35.         fprintf(stderr,"Usage: %s [infile]\n", argv[0]);
  36.         exit(1);
  37.     }
  38.     if (argc == 2) 
  39.         if ( (infile = fopen(argv[1],"r")) == (FILE *)NULL) {
  40.             fprintf(stderr,"%s: Can't open %s for reading\n",
  41.                 argv[0], argv[1]);
  42.             exit(1);
  43.         }
  44.  
  45.     convert(infile, stdout);
  46.     exit(0);
  47. }
  48.  
  49. convert(a,b)
  50.     FILE *a,*b;
  51. {
  52.     static char line[MAX_LINE_LEN];
  53.  
  54.     while (fgets(line,MAX_LINE_LEN,a)) {
  55.        process_line(line, b);
  56.     }
  57. }
  58.  
  59. process_line(line, b)
  60.     char *line;
  61.     FILE *b;
  62. {
  63.     static long line_no=0;
  64.  
  65.     line_no++;
  66.  
  67.     switch(line[0]) {        /* control character */
  68.        case '?': {            /* interactive help entry */
  69.           break;            /* ignore */
  70.        }
  71.        case '@': {            /* start/end table */
  72.           break;            /* ignore */
  73.        }
  74.        case '#': {            /* latex table entry */
  75.           break;            /* ignore */
  76.        }
  77.        case '%': {            /* troff table entry */
  78.           break;            /* ignore */
  79.        }
  80.        case '\n':            /* empty text line */
  81.        case ' ': {            /* normal text line */
  82.           break;
  83.        }
  84.        default: {
  85.           if (isdigit(line[0])) { /* start of section */
  86.                   /* ignore */
  87.           } else
  88.             fprintf(b, "%ld:%s", line_no, line);    /* output bad line */
  89.           break;
  90.        }
  91.     }
  92. }
  93.  
  94.